package ui.face
{

	import com.greensock.plugins.VolumePlugin;

	import common.loader.LoaderManager;
	import common.loader.LoaderType;

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;

	import globals.ButtonType;
	import globals.Global;

	import ui.component.Button;
	import ui.component.Label;
	import ui.component.TextButton;

	import util.TextStyle;
	import util.UIUtil;

	public class UserFace extends Sprite
	{
		private var nameLabel:Label;
		private var levelLabel:Label;
		private var expBar:Bar;
		private var face:Bitmap;

		public function UserFace()
		{
			var bg:Bitmap = new Bitmap(Global.assetsManager.getAssetsAsBitmapData("user_face_bg"));
			bg.x = 5;
			bg.y = 5;
			this.addChild(bg);

			face = new Bitmap();
			/*var circleMask:Shape = new Shape();
			   circleMask.graphics.beginFill(0xFFFFFF);
			   circleMask.graphics.drawCircle(0, 0, 25);
			 face.mask = circleMask;*/
			face.x = 11;
			face.y = 11;
			this.addChild(face);

			nameLabel = new Label(12, 0xFFFFFF, true, "left", true);
			nameLabel.x = 70;
			nameLabel.y = 17;
			addChild(nameLabel);

			expBar = new Bar("face_experience_front", "face_experience_bg", true);
			expBar.x = 70;
			expBar.y = 40;
			expBar.textField.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 11, true);
			TextStyle.addTextFrame(expBar.textField, TextStyle.fontBorderColor);
			this.addChild(expBar);

			levelLabel = new Label(12, 0xfcff00, true, "left", true);
			levelLabel.x = 150;
			levelLabel.y = 17;
			this.addChild(levelLabel);

			var addMoney:TextButton = UIUtil.getTextButton(0, "充值", ButtonType.BUTTON_YELLOW_SMALL, btnHandler);
			addMoney.x = 4;
			addMoney.y = 67;
			this.addChild(addMoney);

			var taskBtn:Button = new Button(Global.assetsManager.getAssetsAsBitmapData("task_icon"));
			taskBtn.clickCallback = btnHandler;
			taskBtn.x = 4;
			taskBtn.y = 155;
			this.addChild(taskBtn);
			//TODO:测试
			updateFace("remote/avatar1.png");
//			updateName("英雄名字");
//			updateExp(10, 30);
//			updateLevel(3);
		}

		private function btnHandler(button:Button):void
		{
			switch(button.id)
			{
				case 0:
					break;
				case 1:
					break;
			}
		}

		public function updateName(value:String):void
		{
			nameLabel.text = value;
		}

		public function updateExp(current:uint, total:uint):void
		{
			expBar.update(current, total);
		}

		private function date():void
		{
		}

		public function updateLevel(level:uint):void
		{
			levelLabel.text = "等级：" + level.toString();
		}

		public function updateFace(url:String):void
		{
			LoaderManager.add(url, LoaderType.IMAGE, faceHandler);
		}

		private function faceHandler(data:BitmapData):void
		{
			face.bitmapData = data;
		}

		public function clear():void
		{
			nameLabel.text = levelLabel.text = "";
		}
	}
}